local xiayuan = fk.CreateSkill {

  name = "joy_mou__xiayuan",

  tags = {  },

}



xiayuan:addEffect(fk.EnterDying, {
  name = "joy_mou__xiayuan",
  anim_type = "support",
  events = {fk.EnterDying},
  can_trigger = function(self, event, target, player, data)
      return player:hasSkill(xiayuan.name) and target ~= player and not player:isNude() and
        player:usedSkillTimes(xiayuan.name, Player.HistoryRound) == 0
  end,
  on_cost = function(self, event, target, player, data)
      local cards = player.room:askForDiscard(player, 1, 2, true, xiayuan.name, true, ".", "#joy_mou__xiayuan-invoke::"..target.id)
      if #cards > 0 then
        event:setCostData(self, #cards)
        return true
      end
  end,
  on_use = function(self, event, target, player, data)
    local n = event:getCostData(self)
    if target:isWounded() then
      player.room:recover({
        who = target,
        num = math.min(target.maxHp - target.hp,n),
        recoverBy = player,
        skillName = xiayuan.name
        })
    end
  end,
})

return xiayuan